< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03090301.xhp

(section: gosubreturn) (bookmark: bm_id3147242)
GoSub...Return statement

GoSub...Return; ステートメント

GoSub...Return Statement [Runtime]
GoSub...Return ステートメント [実行時](hd_id3147242.1)

Calls a subroutine that is indicated by a label from a subroutine or a function. The statements following the label are executed until the next Return statement. Afterwards, the program continues with the statement that follows the GoSub statement.
サブルーチンや関数中から、ラベルで指定するサブルーチンを呼び出します。ラベルの指定先にあるステートメント群は、最初に出現する Return ステートメントの位置までが実行されます。これらのステートメント群の実行後、プログラムの処理行は、呼び出し元の GoSub ステートメントの次行にあたるステートメントに戻ります。(par_id3145316.2)

(/section: gosubreturn)

Syntax:
構文:(hd_id3145609.3)

see Parameters
パラメータを参照(par_id3145069.4)

Parameters:
パラメータ:(hd_id3147265.5)

Sub/Function
Sub/Function(par_id3148664.6)

statement block
ステートメントブロック(par_id3150400.7)

Label
Label(par_id3154140.8)

statement block
ステートメントブロック(par_id3150869.9)

GoSub Label
GoSub Label(par_id3154909.10)

Exit Sub/Function
Exit Sub/Function(par_id3153969.11)

Label:
Label:(par_id3154685.12)

statement block
ステートメントブロック(par_id3145786.13)

Return
Return(par_id3159252.14)

End Sub/Function
End Sub/Function(par_id3154321.15)

The GoSub statement calls a local subroutine indicated by a label from within a subroutine or a function. The name of the label must end with a colon (":").
GoSub ステートメントは、ラベルで指定するローカルサブルーチンを、サブルーチンや関数内で呼び出します。ラベル位置の指定では、ラベル名に続けて末尾にコロン (:) を付ける必要があります。(par_id3147318.16)

Warning Icon 警告マーク If the program encounters a Return statement not preceded by GoSub, Office Basic returns an error message. Use Exit Sub or Exit Function to ensure that the program leaves a Sub or Function before reaching the next Return statement.
プログラムの実行時に、対応する GoSub の存在しない Return ステートメントに遭遇すると、Office Basic からエラーメッセージが返されます。 こうした不適切な Return ステートメントの実行を避けるには、必要な箇所に Exit Sub ないし Exit Function を記述して、該当する Sub や Function を明示的に終了させる必要があります。(par_id3153190.17)

The following example demonstrates the use of GoSub and Return. By executing a program section twice, the program calculates the square root of two numbers that are entered by the user.
下記の例は、GoSubReturn を使用したサンプルコードです。ここではユーザーに 2 つの値を入力させていますが、これらの平方根の計算は、共通の処理セクションを 2 度呼び出すことで処理しています。(par_id3145799.19)

Example:
例:(hd_id3156284.20)

Sub ExampleGoSub
Sub ExampleGoSub(par_id3151073.21)

dim iInputa as Single
dim iInputa as Single(par_id3154097.22)

dim iInputb as Single
dim iInputb as Single(par_id3150715.23)

dim iInputc as Single
dim iInputc as Single(par_id3153416.24)

iInputa = Int(InputBox$ "Enter the first number: ","NumberInput"))
iInputa = Int(InputBox$ ("Enter the first number:","NumberInput"))(par_id3146970.25)

iInputb = Int(InputBox$ "Enter the second number: ","NumberInput"))
iInputb = Int(InputBox$ ("Enter the second number:","NumberInput"))(par_id3150329.26)

iInputc=iInputa
iInputc=iInputa(par_id3156277.27)

GoSub SquareRoot
GoSub SquareRoot(par_id3150321.28)

Print "The square root of";iInputa;" is";iInputc
Print "The square root of";iInputa;" is";iInputc(par_id3154756.29)

iInputc=iInputb
iInputc=iInputb(par_id3155764.30)

GoSub SquareRoot
GoSub SquareRoot(par_id3152960.31)

Print "The square root of";iInputb;" is";iInputc
Print "The square root of";iInputb;" is";iInputc(par_id3147340.32)

Exit Sub
Exit Sub(par_id3166450.33)

SquareRoot:
SquareRoot:(par_id3155176.34)

iInputc=sqr(iInputc)
iInputc=sqr(iInputc)(par_id3149257.35)

Return
Return(par_id3146316.36)

End Sub
End Sub(par_id3154703.37)


< Prev / Next >